package cn.sc.summer.calculate.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.sc.summer.calculate.form.GetSmsLogPageForm;
import cn.sc.summer.calculate.mapper.SmsLogMapper;
import cn.sc.summer.calculate.service.SmsLogService;
import cn.sc.summer.calculate.vo.SmsLogVO;
import cn.sc.summer.constant.model.PageResult;
import cn.sc.summer.constant.sms.SmsLog;
import cn.sc.summer.mybatis.annotation.dynamicdatasource.DataSource;
import cn.sc.summer.mybatis.enums.DataSourceEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 类名：短信下发日志操作业务层
 *
 * @author a-xin
 * @date 2024/2/7 16:43
 */
@Slf4j
@Service
public class SmsLogServiceImpl implements SmsLogService {

    @Resource
    private SmsLogMapper smsLogMapper;

    /**
     * 分页获取短信下发访问日志
     *
     * @param form 分页请求表单
     * @return 短信下发日志
     */
    @Override
    @DataSource(DataSourceEnum.POST_GRE_SQL)
    public PageResult<SmsLogVO> getSmsLog(GetSmsLogPageForm form) {
        return smsLogMapper.selectPage(form, new LambdaQueryWrapper<SmsLog>()
                        .eq(StrUtil.isNotBlank(form.getPhone()), SmsLog::getPhone, form.getPhone()),
                SmsLogVO.class);
    }
}
